package com.cn.pack.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import org.springframework.stereotype.Service;

@Service
public class TestService {

    //开启hystrix缓存
    @CacheResult
    @HystrixCommand(commandKey = "say")
    public String get(@CacheKey Integer id) {
        //String result = restTemplate.getForObject("http://localhost:8080/hello/say/999", String.class);
        String result = "-------------- get";
        System.out.println("result = " + result);
        return result;
    }

    //缓存清除
    @CacheRemove(commandKey = "say") //在指定了@HystrixCommand的commandKey后，在@CacheRemove也要指定相同的commandKey
    @HystrixCommand
    public void set(@CacheKey Integer id) {
        System.out.println("---------- set");
    }
}
